package bit.pja.wolfkill.aop;

import bit.pja.wolfkill.entity.Record;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
@Component
public class RecordAspect {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public static final int WOLF = 1;
    public static final int PROPHET = 2;
    public static final int WIZARD_POISON = 3;
    public static final int WIZARD_DRUG = 4;
    public static final int WIZARD_NO = 5;

    public static final int HUNTER = 6;
    public static final int VILLIGER = 7;

    @AfterReturning(pointcut = "execution(public * bit.pja.wolfkill.Service.GameService.insertRecord(..))", returning = "record")
    public void doAfter(Record record) {
        logger.info(record.toString());
    }

//    @Around(value = "execution(public * bit.pja.wolfkill.Service.GameService.flagEvents(..)&&args(record))")
    public void doAround(ProceedingJoinPoint joinPoint) throws Throwable{
        try {

            joinPoint.proceed();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

//    @Around(value = "execution(public * bit.pja.wolfkill.Service.GameService.progress(..))")
    public void doAroundProcess(ProceedingJoinPoint joinPoint) throws Throwable{
        try {
            logger.info("progress Before Around");
            joinPoint.proceed();
            logger.info("progress After Around");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
